<template>
  <div>
    <div class="jaguar-control">
      <el-button type="primary" @click="handleCreate">新增</el-button>
    </div>

    <div class="jaguar-table">
      <el-table :data="tableData">
        <el-table-column prop="id" label="ID" />
        <el-table-column prop="codeTemplateName" label="模板名称" />
        <el-table-column prop="fileName" label="文件名" />
        <el-table-column prop="filePath" label="文件路径" />
        <el-table-column
          prop="codeTemplateVersion"
          label="模板版本"
          width="100"
        />
        <el-table-column prop="updateTime" label="修改时间" width="180" />
        <el-table-column label="操作" width="160">
          <template #default="scope">
            <el-button
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
              >编辑</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>

    <Edit :dialog="dialog" @success="getData()" />
  </div>
</template>
<script>
import { fetchList } from '@/api/codegen/codeTemplate'
import Edit from './Edit'

export default {
  name: 'Template',
  data() {
    return {
      tableData: [],
      dialog: {
        entity: null,
        visible: false,
      },
    }
  },
  components: {
    Edit,
  },
  created() {
    this.getData()
  },
  methods: {
    getData() {
      fetchList().then((res) => {
        this.tableData = res.data.data
      })
    },
    handleCreate() {
      this.dialog.entity = null
      this.dialog.visible = true
    },
    handleUpdate(row) {
      this.dialog.entity = row
      this.dialog.visible = true
    },
  },
}
</script>
